$(function(){
	var $container = $('#container');
      $container.masonry({
        itemSelector: '.item',
		isAnimated:true,//是否使用动画，默认false
		isFitWidth:true //自动居中
      });

    $container.infinitescroll({
      navSelector  : '#page-nav',    // 导航的选择器，会被隐藏
      nextSelector : '#page-nav a',  // 包含下一页链接的选择器
      itemSelector : '.item',     // 你将要取回的选项(内容块)
	  loading: {
          finishedMsg: '<em>暂无更多结果</em>',
          msgText: '<em>加载中……</em>',
          img: 'http://kuping.wallba.com/Public/masonry-site/images/loading.gif'
      }

    },
    function( newElements ) {
        var $newElems = $( newElements ).css({ opacity: 0 });
         	$newElems.animate({ opacity: 1 });
			$newElems.children(".example").fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',

				'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.9,
				
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
							return '<button onclick="downimg(\''+currentArray[currentIndex].href+'\')";>下载</button>';
						}
			});
         	$container.masonry( 'appended', $newElems, false);
      }
    );
	$(".example").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
						
		'titlePosition'		: 'outside',
		'overlayColor'		: '#000',
		'overlayOpacity'	: 0.9,
		
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
							//alert(currentArray[currentIndex].href);
							return '<button onclick="downimg(\''+currentArray[currentIndex].href+'\')";>下载</button>';
							return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
						}
				
	});
	$("#top_close_btn").click(function(){
		$("#lay_topfixed").slideToggle("show");
	});
});

function downimg(href){
	if(window.external.wappDownloadFiles(href,'jpg',false)){
		//window.external.wappDownloadFiles(href,'jpg,gif,png',false);
		//window.external.wappDownloadFiles(href,'jpg',false);
		return false;
	}else{
		window.open(href);
	}
	return true;
}